// const { loadavg } = require("os");

function scroll(ops = {}) {
    scrollbox = ops.scrollbox;
    imgbox1 = ops.imgbox1;
    imgbox2 = ops.imgbox2;
    // imgs = ops.imgs;
    console.log(this)
    load()
    console.log(window.imgs)


    for (let i = 0; i < imgs.length; i++) {
        let img = document.createElement("img");
        img.alt = "图片加载失败";
        img.src = imgs[i].img_001;

        let a = document.createElement("a")
        a.href = "#"
        a.innerHTML = `<img src="${img.img_001}" alt="">`
        imgbox1.appendChild(a)
    }
    for (let i = 0; i < imgs.length; i++) {
        let img = document.createElement("img");
        img.alt = "图片加载失败";
        img.src = imgs[i].img_001;
        let a = document.createElement("a")
        a.href = "#"
        a.click()
        a.innerHTML = `<img src="${img.img_001}" alt="">`
        imgbox2.appendChild(a)
    }
    let ss = imgbox2.offsetLeft;
    function scroll() {
        imgbox1.style.left = (imgbox1.offsetLeft - 1) + "px";
        imgbox2.style.left = (imgbox2.offsetLeft - 1) - ss + "px";
        if (imgbox1.offsetLeft <= -ss) { imgbox1.style.left = ss + "px"; }
        if (imgbox2.offsetLeft <= -ss) { imgbox2.style.left = 0 + "px"; }
    }
    var time;
    function set() {
        time = setInterval(e => {
            scroll();
        }, 15)
    }
    set();
    scrollbox.onmouseenter = function () {
        clearInterval(time);
    }
    scrollbox.onmouseleave = function () {
        set();
    }
}
function load() {
    ajax("http://localhost:3000/getGoods", (res) => {
        res = JSON.parse(res);
        console.log(res.data)
        console.log(this)
        imgs = res.data
        
    })

}